package com.boot.util;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Random;

public class CommonUtils {

	public static String longToDate(Date date){
		System.out.println(date);
		//long neededParseDate=Long.parseLong(longStr);//需要转换的时间
		SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
        //将毫秒数字符串时间转成long值
        //long addtime=Long.parseLong(longtime);
        return sdf.format(date.getTime());
		
//		Date now=new Date();//当前时间
//		long nowlong=now.getTime();//当前时间毫秒数
//		long neededParseDate=Long.parseLong(longStr);//需要转换的时间\
//		Date parsedDate=new Date(neededParseDate);
//		//先判断年
//		int nowyear=now.getYear();//当前时间的年份
//		int parseYear=parsedDate.getYear();
//		if(nowyear==parseYear){//发布时间为本年,可将年省略比如:6月16日,10天前,10个小时前,5分钟前,刚刚
//			long dlong=(nowlong-neededParseDate)/1000;//秒数之差
//			if(dlong<60){//刚刚
//				System.out.println("刚刚");
//				//return "刚刚";
//			}else if(dlong<60*60){//1小时内
//				System.out.println(dlong/60+"分钟前");
//				//return dlong/60+"分钟前";
//			}else if(dlong<60*60*24){//24小时内
//				System.out.println(dlong/(60*60)+"小时前");
//				//return dlong/(60*24)+"小时前";
//			}else if(dlong<60*60*24*28){//1个月内
//				System.out.println(dlong/(60*60*24)+"天前");
//				//return dlong/(60*60*24)+"天前");
//			}else {//超过1个月直接显示成6月15日的格式
//				System.out.println((parsedDate.getMonth()+1)+"月"+parsedDate.getDate()+"日");
//			}
//		}else{//整个时间带有年比如:2018年6月16日
//			System.out.println(parseYear%100+"年"+(parsedDate.getMonth()+1)+"月"+parsedDate.getDate()+"日");
//		}
	}
	
	/**
	 * 生成token
	 * @param photo
	 * @return
	 */
	public static String makeToken(String phone){
		String token="";
		String[] letters={"a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"};
		Random rand=new Random();
		Date date=new Date();
		long time=date.getTime();
		String dateAndPhotoStr=time+phone;
		String[] numbers=dateAndPhotoStr.split("");
		for(int i=0;i<24;i++){
			int randNum=rand.nextInt(25);
			token+=letters[randNum]+numbers[randNum];
		}
		return token;
	}
	
	
	
	public static void main(String[] args) {
		String token=makeToken("15244367073");
		System.out.println(token);
	}
	
}
